<?php
require_once ($_SESSION ['pathway'] . "/commun/ouvre_base.php");
// ~ $link = mysqli_connect($host, $userbase, $passwd) or die('Impossible de se connecter pour récupérer niveau : ' . mysql_error());
mysql_select_db ( $db ) or die ( 'Impossible de s&#233;lectionner la base de donn&#233;es' );
// ~ mysqli_select_db($link,$db) or die('Impossible de s&#233;lectionner la base de donn&#233;es');

$hash_champ_UHDRS = array ();
$hash_champ_UHDRS = $_SESSION ['hash_UHDRS'];

// remplissage des valeurs dans la table UHDRS
if (isset ( $_POST ['question_43'] )) {
	$question_43 = $_POST ['question_43'];
} else {
	$question_43 = '';
}
if (isset ( $_POST ['question_44'] )) {
	$question_44 = $_POST ['question_44'];
} else {
	$question_44 = '';
}
if (isset ( $_POST ['question_45'] )) {
	$question_45 = $_POST ['question_45'];
} else {
	$question_45 = '';
}
if (isset ( $_POST ['question_46'] )) {
	$question_46 = $_POST ['question_46'];
} else {
	$question_46 = '';
}
if (isset ( $_POST ['question_47'] )) {
	$question_47 = $_POST ['question_47'];
} else {
	$question_47 = '';
}
if (isset ( $_POST ['question_48'] )) {
	$question_48 = $_POST ['question_48'];
} else {
	$question_48 = '';
}
if (isset ( $_POST ['question_49'] )) {
	$question_49 = $_POST ['question_49'];
} else {
	$question_49 = '';
}
if (isset ( $_POST ['question_50'] )) {
	$question_50 = $_POST ['question_50'];
} else {
	$question_50 = '';
}
if (isset ( $_POST ['question_51'] )) {
	$question_51 = $_POST ['question_51'];
} else {
	$question_51 = '';
}
if (isset ( $_POST ['question_52'] )) {
	$question_52 = $_POST ['question_52'];
} else {
	$question_52 = '';
}
if (isset ( $_POST ['question_53'] )) {
	$question_53 = $_POST ['question_53'];
} else {
	$question_53 = '';
}
if (isset ( $_POST ['question_54'] )) {
	$question_54 = $_POST ['question_54'];
} else {
	$question_54 = '';
}
if (isset ( $_POST ['question_55'] )) {
	$question_55 = $_POST ['question_55'];
} else {
	$question_55 = '';
}
if (isset ( $_POST ['question_56'] )) {
	$question_56 = $_POST ['question_56'];
} else {
	$question_56 = '';
}
if (isset ( $_POST ['question_57'] )) {
	$question_57 = $_POST ['question_57'];
} else {
	$question_57 = '';
}
if (isset ( $_POST ['question_58'] )) {
	$question_58 = $_POST ['question_58'];
} else {
	$question_58 = '';
}
if (isset ( $_POST ['question_59'] )) {
	$question_59 = $_POST ['question_59'];
} else {
	$question_59 = '';
}
if (isset ( $_POST ['question_60'] )) {
	$question_60 = $_POST ['question_60'];
} else {
	$question_60 = '';
}
if (isset ( $_POST ['question_61'] )) {
	$question_61 = $_POST ['question_61'];
} else {
	$question_61 = '';
}
if (isset ( $_POST ['question_62'] )) {
	$question_62 = $_POST ['question_62'];
} else {
	$question_62 = '';
}
if (isset ( $_POST ['question_63'] )) {
	$question_63 = $_POST ['question_63'];
} else {
	$question_63 = '';
}
if (isset ( $_POST ['question_64'] )) {
	$question_64 = $_POST ['question_64'];
} else {
	$question_64 = '';
}
if (isset ( $_POST ['question_65'] )) {
	$question_65 = $_POST ['question_65'];
} else {
	$question_65 = '';
}
if (isset ( $_POST ['question_66'] )) {
	$question_66 = $_POST ['question_66'];
} else {
	$question_66 = '';
}
if (isset ( $_POST ['question_67'] )) {
	$question_67 = $_POST ['question_67'];
} else {
	$question_67 = '';
}
if (isset ( $_POST ['information_source'] )) {
	$information_source = $_POST ['information_source'];
} else {
	$information_source = '';
}

$score_UHDRS = $question_43 + $question_44 + $question_45 + $question_46 + $question_47 + $question_48 + $question_49 + $question_50 + $question_51 + $question_52 + $question_53 + $question_54 + $question_55 + $question_56 + $question_57 + $question_58 + $question_59 + $question_60 + $question_61 + $question_62 + $question_63 + $question_64 + $question_65 + $question_66 + $question_67;
$_SESSION ['score_UHDRS'] = $score_UHDRS;

$query_remplissage_score_UHDRS = "UPDATE `$db`.`diagnostic` SET `score_UHDRS` = '$score_UHDRS' WHERE `diagnostic`.`form` = " . $_SESSION ['form'];
mysql_query ( $query_remplissage_score_UHDRS ) or die ( "impossible de remplir le score UHDRS : " . mysql_error () );
// ~ mysqli_query($link,$query_remplissage_score_UHDRS) or die("impossible de remplir le score UHDRS : " . mysql_error());

$hash_UHDRS = array (
		"form" => $_SESSION ['form'],
		"question_43" => $question_43,
		"question_44" => $question_44,
		"question_45" => $question_45,
		"question_46" => $question_46,
		"question_47" => $question_47,
		"question_48" => $question_48,
		"question_49" => $question_49,
		"question_50" => $question_50,
		"question_51" => $question_51,
		"question_52" => $question_52,
		"question_53" => $question_53,
		"question_54" => $question_54,
		"question_55" => $question_55,
		"question_56" => $question_56,
		"question_57" => $question_57,
		"question_58" => $question_58,
		"question_59" => $question_59,
		"question_60" => $question_60,
		"question_61" => $question_61,
		"question_62" => $question_62,
		"question_63" => $question_63,
		"question_64" => $question_64,
		"question_65" => $question_65,
		"question_66" => $question_66,
		"question_67" => $question_67,
		"information_source" => $information_source 
);

foreach ( $hash_UHDRS as $key => $value ) {
	if ($value != '') {
		$value = mysql_real_escape_string ( $value );
		// ~ $value = mysqli_real_escape_string($link,$value);
		$value = str_replace ( ',', '.', $value );
		$query_update_form = "UPDATE `" . $db . "`.`uhdrs` SET `$key` = '$value' WHERE `uhdrs`.`form` = " . $_SESSION ['form'];
		// echo $query_update_form;
		mysql_query ( $query_update_form ) or die ( "impossible d'updater la form : " . mysql_error () );
		// ~ mysqli_query($link,$query_update_form) or die("impossible d'updater la form : " . mysql_error());
	} else {
		$query_update_form = "UPDATE `" . $db . "`.`uhdrs` SET `$key` = NULL WHERE `uhdrs`.`form` = " . $_SESSION ['form'];
		mysql_query ( $query_update_form ) or die ( "impossible d'updater la form : " . mysql_error () );
		// ~ mysqli_query($link,$query_update_form) or die("impossible d'updater la form : " . mysql_error());
	}
}

?>
